package votes

import (
	"context"
	"gitee.com/shijun123456/srpcinterface/client"
	"gitee.com/shijun123456/srpcinterface/client/votes"
)

//这里定义请求信息
// 用户的请求信息
// protobuf 自动生成的
//这里是签名信息
//
type (
	ActidReq       = votes.ActidReq
	ActInfoReq =   votes.ActInfoReq
	ActInfoResp = votes.ActInfoResp
	EnrollInfoReq = votes.EnrollInfoReq
	EnrollResp = votes.EnrollResp
	EnrollListResp = votes.EnrollListResp
	EnrollReq = votes.EnrollReq
	VotesReq = votes.VotesReq
	VotesResp = votes.VotesResp
)

type Voter interface {
	//获取作品信息
	GetEnrollInfo(context.Context, *EnrollInfoReq) (*EnrollResp, error)
	//获取 作品列表
	GetEnrollList(context.Context, *ActidReq) (*EnrollListResp, error)
	//获取 活动信息
	GetActivityInfo(context.Context, *ActInfoReq) (*ActInfoResp, error)
	//报名
	Enroll(context.Context, *EnrollReq) (*EnrollResp, error)
	//投票
	Votes(context.Context, *VotesReq) (*VotesResp, error)
	//增加活动的爆光量
	IncrActiviView(context.Context, *ActInfoReq) (*ActInfoResp, error)
}

//默认用户的客户端
type Vote struct {
	c           client.Client
	servicename string //服务的名称信息
	servicepath string //服务path 信息 服务信息 call path/method
	client votes.VotesClient
}

func (v Vote) GetEnrollInfo(ctx context.Context, req *EnrollInfoReq) (*EnrollResp, error) {
	return v.client.GetEnrollInfo(ctx,req)
}

func (v Vote) GetEnrollList(ctx context.Context, req *ActidReq) (*EnrollListResp, error) {
	return v.client.GetEnrollList(ctx,req)
}

func (v Vote) GetActivityInfo(ctx context.Context, req *ActInfoReq) (*ActInfoResp, error) {
	return v.client.GetActivityInfo(ctx,req)
}

func (v Vote) Enroll(ctx context.Context, req *EnrollReq) (*EnrollResp, error) {
	return v.client.Enroll(ctx,req)
}

func (v Vote) Votes(ctx context.Context, req *VotesReq) (*VotesResp, error) {
	return v.client.Votes(ctx,req)
}

func (v Vote) IncrActiviView(ctx context.Context, req *ActInfoReq) (*ActInfoResp, error) {
	return v.client.IncrActiviView(ctx,req)
}

func New() *Vote {
	return &Vote{}
}
func (f *Vote) Init() *Vote {
	f.servicepath = "VoteService"
	f.servicename = "vote.svc"
	f.c.Init(f) //初始化信息
	f.client = votes.NewVotesClient(f.c.Conn())
	return f
}

//接口信息
func (f *Vote) GetServiceName() string {
	return f.servicename
}
func (f *Vote) Close() {
	f.c.PutConn(f.c.Conn())
	f.c.PoolClose()
	f.c.Conn().Close()
}
